package com.wondertek.web.controller.business;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wondertek.common.base.Result;
import com.wondertek.common.util.security.PreAuthorize;
import com.wondertek.service.dto.app.req.AddModeTimedTaskReq;
import com.wondertek.service.dto.app.req.AppRoomUpdateModeReq;
import com.wondertek.service.dto.business.req.ModeTimedTaskFindReq;
import com.wondertek.service.dto.business.req.RoomAddReq;
import com.wondertek.service.dto.business.req.RoomPageReq;
import com.wondertek.service.dto.business.req.RoomUpdateReq;
import com.wondertek.service.dto.business.res.RoomPageRes;
import com.wondertek.service.dto.sys.req.BaseUpdateReq;
import com.wondertek.service.entity.business.IndustryPo;
import com.wondertek.service.entity.business.RoomPo;
import com.wondertek.service.sdk.iotdh.dto.res.SetAreaArmModeRes;
import com.wondertek.service.service.business.IndustryService;
import com.wondertek.service.service.business.RoomService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: 房间管理
 * @author: qinjianhui
 * @create: 2024-07-16 14:01
 **/
@RestController
@RequestMapping("/backend/business/room/")
@Tag(name = "房间管理")
public class RoomController {

    @Resource
    private RoomService roomService;

    @Resource
    private IndustryService industryService;

    @PostMapping("/selectIndustry")
    @Operation(summary = "查询行业")
    public Result<List<IndustryPo>> selectIndustry(){
        List<IndustryPo> list = industryService.list();
        return Result.success(list);
    }

    @PostMapping("/add")
    @Operation(summary = "新增房间")
    @PreAuthorize("@el.check('backend:business:room:add')")
    public Result<?> addRoom(@RequestBody @Validated RoomAddReq adminAddReq){
        roomService.addRoom(adminAddReq);
        return Result.success();
    }

    @PostMapping("/delete")
    @Operation(summary = "删除房间")
    @PreAuthorize("@el.check('backend:business:room:delete')")
    public Result<?> deleteRoom(@RequestBody @Validated BaseUpdateReq baseUpdateReq){
        roomService.deleteRoom(baseUpdateReq.getId());
        return Result.success();
    }

    @PostMapping("/page")
    @Operation(summary = "分页查询房间")
    public Result<Page<RoomPo>> page(@RequestBody RoomPageReq roomPageReq){
        return Result.success(roomService.page(roomPageReq));
    }

    /**
     * 查询网关设备-房间列表
     * @param roomPageReq
     * @return
     */
    @PostMapping("/roomPage")
    @Operation(summary = "查询网关设备-房间列表")
    @PreAuthorize("@el.check('backend:business:room:roomPage')")
    public Result<Page<RoomPageRes>> roomPage(@RequestBody RoomPageReq roomPageReq){
        return Result.success(roomService.roomPage(roomPageReq));
    }

    @PostMapping("/update")
    @Operation(summary = "修改房间")
    @PreAuthorize("@el.check('backend:business:room:update')")
    public Result<?> updateRoom(@RequestBody @Validated RoomUpdateReq updateReq){
        roomService.updateRoom(updateReq);
        return Result.success();
    }

    @PostMapping("/selectByDevice")
    @Operation(summary = "根据设备查询分区")
    public Result<List<RoomPo>> selectByDevice(@RequestBody BaseUpdateReq req){
        return Result.success(roomService.selectByDevice(req.getId()));
    }

    @PostMapping("/updateMode")
    @Operation(summary = "更改布防模式")
    @PreAuthorize("@el.check('backend:business:room:updateMode')")
    public Result<SetAreaArmModeRes> updateMode(@RequestBody @Validated AppRoomUpdateModeReq req){
        return roomService.updateMode(req);
    }

    /**
     * 新增定时布撤防
     *
     * @param req
     */
    @PostMapping("/addModeTimedTask")
    @Operation(summary = "新增定时布撤防")
    public Result addModeTimedTask(@RequestBody @Validated AddModeTimedTaskReq req) {
        roomService.addModeTimedTask(req);
        return Result.success();
    }

    /**
     * 修改定时布撤防
     * @param req
     */
    @PostMapping("/updModeTimedTask")
    @Operation(summary = "修改定时布撤防")
    public Result updModeTimedTask(@RequestBody @Validated AddModeTimedTaskReq req){
        roomService.updModeTimedTask(req);
        return Result.success();
    }


    @PostMapping("/findModeTimedTask")
    @Operation(summary = "查询定时布撤防")
    public Result<Page<AddModeTimedTaskReq>> findModeTimedTask(@RequestBody @Validated  ModeTimedTaskFindReq modeTimedTaskFindReq) {
            return Result.success(roomService.findModeTimedTask(modeTimedTaskFindReq));
    }

    /**
     * 暂停/启动 定时布撤防任务
     * @param taskId
     * @param status
     */
    @GetMapping("/onOffModeTimedTask")
    @Operation(summary = "暂停/启动 定时布撤防任务")
    public Result onOffModeTimedTask(@RequestParam("taskId") String taskId, @RequestParam("status") Integer status){
        roomService.onOffModeTimedTask(taskId, status);
        return Result.success();
    }

    /**
     * 删除定时布撤防任务
     * @param taskId
     */
    @GetMapping("/delModeTimedTas")
    @Operation(summary = "删除定时布撤防任务")
    public Result delModeTimedTas(@RequestParam("taskId") String taskId){
        roomService.delModeTimedTas(taskId);
        return Result.success();
    }

}

